<template>
	<el-config-provider :locale="config.locale" :size="config.size" :zIndex="config.zIndex" :button="config.button">
		<router-view></router-view>
	</el-config-provider>
</template>

<script>
	import colorTool from '@/utils/color'
	import tool from "@/utils/tool";

	export default {
		name: 'App',
		data() {
			return {
				config: {
					locale: this.$i18n.messages[this.$i18n.locale].el,
					size: "default",
					zIndex: 2000,
					button: {
						autoInsertSpace: false
					}
				}
			}
		},
		created() {
			//设置主题颜色
			const app_color = this.$TOOL.data.get('APP_COLOR') || this.$CONFIG.COLOR
			if(app_color){
				document.documentElement.style.setProperty('--el-color-primary', app_color);
				for (let i = 1; i <= 9; i++) {
					document.documentElement.style.setProperty(`--el-color-primary-dark-${i}`, colorTool.darken(app_color,i/10));
					document.documentElement.style.setProperty(`--el-color-primary-light-${i}`, colorTool.lighten(app_color,i/10));
				}
				document.documentElement.style.setProperty(`--el-color-primary-darken-1`, colorTool.darken(app_color,0.1));
			}
		},
		mounted() {
			tool.data.set("INVALID_PERMISSION_MESSAGE",false);
			//this.reloadUserInfo();
			//this.reloadMenu();
		},
		methods:{
				async reloadMenu() {
					var token = this.$TOOL.data.get("TOKEN");
					if(!token)return;
					var menu = await this.$API.system.menu.myMenus.get()
					if (menu.success) {
						this.$TOOL.data.set("MENU", menu.data.menuList)
						this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
					}
				},
				async reloadUserInfo() {
					var token = this.$TOOL.data.get("TOKEN");
					if(!token)return;
					var user = await this.$API.system.user.info.get(token)
					if (user.success) {
						this.$TOOL.data.set("USER_INFO", user.data);
						this.$TOOL.handleCustomConfig(user.data.personalConfigs);
					}
				},
		}
	}
</script>

<style lang="scss">
	@import '@/style/style.scss';
</style>
